//
//  BIDInfoBriefListViewController.m
//  JuanChengOA
//
//  Created by mal on 2017/7/19.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDInfoBriefListViewController.h"
#import "BIDInfoBriefDetailViewController.h"

static NSString *listURL = @"townAndroid!gainReceiveTownWorkList.action";

@interface BIDInfoBriefListViewController ()<BIDBaseListViewDelegate>

@end

@implementation BIDInfoBriefListViewController
@synthesize type;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)loadData
    {
        self.curPage++;
        NSString *strRequestURL = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getServerAddr], listURL];
        NSString *strPost = [[NSString alloc] initWithFormat:@"page=%ld&rows=%ld&userId=%@&type=%@", self.curPage, self.countPerPage, [AppDelegate getUserId], type];
        [self sendHttpRequestWithURL:strRequestURL postData:strPost withCompletion:^(NSDictionary *responseDic, NSString *errMsg){
            if(errMsg)
            {
                [self showAlertView:errMsg buttonTitle:ALERT_BTN_TITLE tag:0 functionName:nil];
            }
            else
            {
                NSArray *arr = responseDic[@"rows"];
                [self.dataSourceArr addObjectsFromArray:arr];
                if(self.dataSourceArr.count < self.curPage*self.countPerPage)
                {
                    [self.myTableView hasNoMoreData];
                }
                else
                {
                    [self.myTableView hasMoreData];
                }
            }
            [self.myTableView reloadData];
        }];
    }

    
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.dataSourceArr.count;
    }
    
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = nil;
        static NSString *identifier = @"identifier";
        NSUInteger row = indexPath.row;
        cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if(!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        }
        NSDictionary *dic = self.dataSourceArr[row][@"townWork"];
        cell.textLabel.text = dic[@"title"];
        cell.textLabel.textColor = RGBACOLOR(50, 54, 59, 1);
        cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"[%@]", dic[@"announceTime"]];
        cell.detailTextLabel.textColor = [UIColor darkGrayColor];
        return cell;
    }
    
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        NSUInteger row = indexPath.row;
        NSDictionary *dic = self.dataSourceArr[row][@"townWork"];
        BIDInfoBriefDetailViewController *vc = [[BIDInfoBriefDetailViewController alloc] initWithNibName:@"BIDInfoBriefDetailViewController" bundle:nil];
        //vc.desURL = self.detailURL;
        vc.infoID = self.dataSourceArr[row][@"id"];
        vc.type = self.type;
        [self.navigationController pushViewController:vc animated:YES];
    }

@end
